package com.local.jodatime.jodabase;

import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.Hours;
import org.joda.time.LocalDate;
import org.joda.time.Minutes;
import org.joda.time.Period;
import org.joda.time.Seconds;

public class SubNormalTime {
	/**
	 * 日期相减1
	 */
	public static void subDate(){
		LocalDate start=new LocalDate(2016, 12,31);  
		LocalDate end=new LocalDate(2016, 12, 30); 
		int days = Days.daysBetween(start, end).getDays();  
		System.out.println("LocalDate格式：相差"+days+"天");
	}
	
	
	/**
	 * 日期相减2(一般很少用这个)
	 */
	public static void subDateHeighter(){
		
        DateTime  start =new DateTime(2016,11,30,22,00,30);
        DateTime end=new DateTime(2016,12,31,22,30,50);
        System.out.println("总共相差"+Days.daysBetween(start,end).getDays()+"天");
        System.out.println("总共相差"+Hours.hoursBetween(start,end).getHours()+"小时");
        System.out.println("总共相差"+Minutes.minutesBetween(start,end).getMinutes()+"分钟");
        System.out.println("总共相差"+Seconds.secondsBetween(start,end)+"秒");
	}
	
	
	/**
	 * 日期相减3(对应列相减,多用于判断方法执行了多久时间)
	 */
	public static void subDateFaster(){

		DateTime  start =new DateTime(2016,11,30,22,00,30);
		DateTime end=new DateTime(2016,12,31,22,30,59);
		Period period=new Period(start,end);
		System.out.println("相差"+period.getMonths()+"月"
				+period.getDays()+"天"
				+period.getHours()+"小时"
				+period.getMinutes()+"分钟"
				+period.getSeconds()+"秒");
	}
	
	public static void main(String[] args) {
		subDate();
		subDateHeighter();
		subDateFaster();
	}
}
